package com.glory.brepda.adapter;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;

import androidx.annotation.Nullable;
import androidx.fragment.app.FragmentManager;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.glory.brepda.R;
import com.glory.brepda.activity.check.QCDetailActivity;
import com.glory.brepda.activity.mfg.WBWorkEnd2Activity;
import com.glory.brepda.activity.mfg.eqpStateCompleteActivity;
import com.glory.brepda.activity.technicalservice.AMDetailActivity;
import com.glory.brepda.entity.EquCallOutStateEntity;
import com.pda.platform.ui.ui_pdaplatform.callback.FreeUI_CommonCallback;
import com.pda.platform.ui.ui_pdaplatform.utils_public.FreeApi_DialogUtils;


import java.util.List;

public class GroupEquStateListAdapter extends BaseQuickAdapter<EquCallOutStateEntity.ResultBean, BaseViewHolder> {
    private boolean mStatus = true;
    private NetworkRequestCallback callback;

    private FragmentManager fragmentManager;

    private Activity activity;
    public GroupEquStateListAdapter(@Nullable List<EquCallOutStateEntity.ResultBean> data, FragmentManager fragmentManager, NetworkRequestCallback callback,Activity activity) {
        super(R.layout.title_equipment_group,data);
        this.fragmentManager = fragmentManager;
        this.callback = callback;
        this.activity = activity;
    }

    @Override
    protected void convert(BaseViewHolder helper, EquCallOutStateEntity.ResultBean item) {
        helper.setText(R.id.tvLocation,item.getLocation());
        helper.setText(R.id.tvCarrierID,item.getAddress_Id());
        helper.setText(R.id.tvSource,item.getSource());
        helper.setText(R.id.tvEument_state,item.getEqumanet_state_name());

        if("CRE".equals(item.getState())){
            helper.setText(R.id.tvState,"未接工");
        }else{
            helper.setText(R.id.tvState,"已接工");
        }

        if ("CRE".equals(item.getState())){
            helper.setText(R.id.tvOperation,"接工");
        }else{
            helper.setText(R.id.tvOperation,"完工");
        }

        if("QC".equals(item.getSource())){
            helper.setText(R.id.tvSource,"QC");
        }else if("TRANSFER".equals(item.getSource())){
            helper.setText(R.id.tvSource,"转工");
        }else{
            helper.setText(R.id.tvSource,"叫修");
        }


        helper.getView(R.id.tvOperation).setOnClickListener(view -> {

            if("CRE".equals(item.getState())){
                FreeApi_DialogUtils.getConfirmAndCancelDialog(mContext, "是否确认接工?", new FreeUI_CommonCallback() {
                    @Override
                    public void onSuccess() {
                        if (callback != null) {
                            String text="";//备注信息在接口里面赋值
                            callback.takeOverRequestPostNet(item.getOBJECTRRN(),item.getState()); // 调用回调方法
                        }
                    }
                }, () -> {}).show(fragmentManager,"CONFIRM_DIALOG");
            }else{
                if("Y".equals(item.getEquCallQCCheckFlag())){
                    Context context = helper.itemView.getContext();
                    Bundle bundle = new Bundle();
                    bundle.putString("LOTID",item.getWip_lot_lot_id());
                    bundle.putString("EQUIPMENT",item.getEquipmentId());
                    bundle.putLong("CALLOUT_MAINTAIN_RRN",item.getOBJECTRRN());
                    bundle.putLong("RAS_EQP_STATE_OBJECT_RRN",item.getRes_eqp_state_object_rrn());
                    Intent intent = new Intent(context, eqpStateCompleteActivity.class);
                    intent.putExtras(bundle);
                    activity.startActivityForResult(intent,1);
                }else{
                    FreeApi_DialogUtils.getConfirmAndCancelDialog(mContext, "是否确认完工?", new FreeUI_CommonCallback() {
                        @Override
                        public void onSuccess() {
                            if (callback != null) {
                                callback.showInputDialog(item); // 调用回调方法
                            }
                        }
                    }, () -> {}).show(fragmentManager,"CONFIRM_DIALOG");
                }
            }

        });
    }

    public interface NetworkRequestCallback{
        void takeOverRequestPostNet(long index,String type);
        void showInputDialog(EquCallOutStateEntity.ResultBean item);

        void goToNextStep(EquCallOutStateEntity.ResultBean item);
    }
}
